package com.hwy.widget.status_bar

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.hwy.widget.R
import com.hwy.widget.utils.StatusBarUtil

/**
 * 状态栏工具类
 */
class StatusBarActivity : AppCompatActivity() {

    companion object {
        /**
         * 是否沉浸式显示
         */
        private const val IMMERSION = "immersion"

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_status_bar)

        intent?.hasExtra(IMMERSION)?.run {
            val translation = intent?.getBooleanExtra(IMMERSION, false) ?: false
            if (translation) {
                StatusBarUtil.translucent(this@StatusBarActivity)
                supportActionBar?.hide()
            }
        }

        findViewById<Button>(R.id.btn_dark_text)?.run {
            setOnClickListener {
                // 设置标题文本深色
                StatusBarUtil.setStatusBarLightMode(this@StatusBarActivity)
            }
        }
        findViewById<Button>(R.id.btn_light_text)?.run {
            setOnClickListener {
                // 设置标题文本浅色
                StatusBarUtil.setStatusBarDarkMode(this@StatusBarActivity)
            }
        }
        findViewById<Button>(R.id.btn_translation)?.run {
            setOnClickListener {
                // 沉浸式状态栏
                val intent = Intent(this@StatusBarActivity, StatusBarActivity::class.java)
                intent.putExtra(IMMERSION, true)
                startActivity(intent)
            }
        }
        findViewById<Button>(R.id.btn_status_bar_height)?.run {
            setOnClickListener {
                // 获取状态栏高度
                Toast.makeText(
                    context,
                    "status bar height = ${StatusBarUtil.getStatusBarHeight(context)}",
                    Toast.LENGTH_SHORT
                ).show()
            }
        }

    }
}